#ifndef __STATE_MACHINE_H__
#define __STATE_MACHINE_H__
#include <typescommon.h>

struct statMcBaseStruct;
struct statMcMngStruct;
typedef int (*stateMachineInit)(struct statMcBaseStruct *thisState);
typedef int (*stateMachineRun)(struct statMcBaseStruct *thisState);
typedef int (*stateMachineQuit)(struct statMcBaseStruct *thisState);
struct statMcBaseStruct
{
    stateMachineInit stateInit;
    stateMachineRun stateRun;
    stateMachineQuit stateQuit;
    int stateId;
    struct statMcMngStruct *stateManager;
};
#define statMcInvalidID (-1)

#define statMcBaseDefine(setinit, setrun, setquit, setid, setManager) \
    {                                                                 \
        setinit, setrun, setquit, setid, setManager}

struct statMcMngStruct
{
    struct statMcBaseStruct *statelist;
    void *stateContext;
    int stateSize;
    int stateIdNow;
    int stateIdNext;
};
// state machine manage init
int statMcMngInit(struct statMcMngStruct *smnger, void *setContext, struct statMcBaseStruct *setStateBuffer,
                  int setStateSize, int initState);
// state machine manage run
int statMcMngRun(struct statMcMngStruct *smnger);
// state machine manage quit
int statMcMngQuit(struct statMcMngStruct *smnger);
// state machine manage transition
int statMcMngTranst(struct statMcMngStruct *smnger, int nextStateId);
#endif